using System;
using System.Collections.Generic;
using System.Linq;
using Granite.Xaml.Internals;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Granite.Xaml.Tests.Helpers;

namespace Granite.Xaml.Tests.Internals
{
	[TestClass]
	public class SimpleNavigatorTests
	{

		[TestMethod]
		public void SimpleNavigator_ForwardBackwardTest()
		{
			var navigator = new SimpleNavigator();
			var navigateAssert = new NavigateAssert(navigator);

			navigator.Navigate(new Uri("/Views/A.xaml", UriKind.Relative));
			navigator.Navigate(new Uri("/Views/B.xaml", UriKind.Relative));
			navigator.Navigate(new Uri("/Views/C.xaml", UriKind.Relative));

			navigateAssert.Expect("/Views/A.xaml");
			navigateAssert.Expect("/Views/B.xaml");
			navigateAssert.Expect("/Views/C.xaml");

			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

			navigator.GoBack();
			navigateAssert.Expect("/Views/B.xaml");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsTrue(navigator.CanGoForward);


			navigator.GoBack();
			navigateAssert.Expect("/Views/A.xaml");
			Assert.IsFalse(navigator.CanGoBack);
			Assert.IsTrue(navigator.CanGoForward);

			navigator.GoForward();
			navigateAssert.Expect("/Views/B.xaml");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsTrue(navigator.CanGoForward);

			navigator.Navigate(new Uri("/Views/D.xaml", UriKind.Relative));
			navigateAssert.Expect("/Views/D.xaml");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

		}

		[TestMethod]
		public void SimpleNavigator_OpenWebsiteTest()
		{
			var navigator = new SimpleNavigator();
			var navigateAssert = new NavigateAssert(navigator);
			var openWebsiteAssert = new OpenWebsiteAssert(navigator);
			navigator.Navigate(new Uri("/Views/A.xaml", UriKind.Relative));
			navigateAssert.Expect("/Views/A.xaml");

			Assert.IsFalse(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

			navigator.OpenWebsite(new Uri("http://test.com/"));
			openWebsiteAssert.Expect("http://test.com/");
			Assert.IsFalse(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

			navigator.IncludeWebInNavigation = true;
			navigator.OpenWebsite(new Uri("http://test.com/"));
			openWebsiteAssert.Expect("http://test.com/");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

			navigator.OpenWebsite(new Uri("http://test2.com/"));
			openWebsiteAssert.Expect("http://test2.com/");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsFalse(navigator.CanGoForward);

			navigator.GoBack();
			navigateAssert.Expect("http://test.com/");
			Assert.IsTrue(navigator.CanGoBack);
			Assert.IsTrue(navigator.CanGoForward);


		}


	}
}
